package testproject;

import DAO.*;
import java.sql.Date;
import java.util.Vector;
import javax.swing.JOptionPane;

public class updateDeleteVacFill extends javax.swing.JFrame {

    VacFillDetailDAO vacFillDao = new VacFillDetailDAO();

    public updateDeleteVacFill() {
        initComponents();
        lblVacFillVacIdCheck.setVisible(false);
        lblVacFillEmpIdCheck.setVisible(false);
        lblVacFillDateCheck.setVisible(false);
        lblVacFillInDetailsCheck.setVisible(false);

        vacFillDao.loadVacFillCombobox(cbVacFillVacId, cbVacFillEmpId);
    }

    public boolean validateVacFillUpdateDelete() {
        if (cbVacFillVacId.getSelectedIndex() == 0) {
            lblVacFillVacIdCheck.setVisible(true);
            cbVacFillVacId.requestFocus();
            return false;
        }
        lblVacFillVacIdCheck.setVisible(false);
        if (cbVacFillEmpId.getSelectedIndex() == 0) {
            lblVacFillEmpIdCheck.setVisible(true);
            cbVacFillEmpId.requestFocus();
            return false;
        }
        lblVacFillEmpIdCheck.setVisible(false);
        if (txtVacFillDate.getText().equals("")) {
            lblVacFillDateCheck.setVisible(true);
            txtVacFillDate.requestFocus();
            return false;
        }
        lblVacFillDateCheck.setVisible(false);
        if (txaVacFillInDetail.getText().equals("")) {
            lblVacFillInDetailsCheck.setVisible(true);
            txaVacFillInDetail.requestFocus();
            return false;
        }
        lblVacFillInDetailsCheck.setVisible(false);
        return true;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cbVacFillVacId = new javax.swing.JComboBox();
        btnVacFillUpdate = new javax.swing.JButton();
        btnVacFillDelete = new javax.swing.JButton();
        lblVacFillVacIdCheck = new javax.swing.JLabel();
        cbVacFillEmpId = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        btnVacFillCancel = new javax.swing.JButton();
        lblVacFillDateCheck = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaVacFillInDetail = new javax.swing.JTextArea();
        lblVacFillInDetailsCheck = new javax.swing.JLabel();
        lblVacFillEmpIdCheck = new javax.swing.JLabel();
        txtVacFillID = new javax.swing.JTextField();
        btnfind = new javax.swing.JButton();
        txtVacFillDate = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(102, 102, 255));
        jLabel1.setText("Vacancy Filling Information");

        jLabel2.setForeground(new java.awt.Color(102, 102, 255));
        jLabel2.setText("Vacancy ID:");

        cbVacFillVacId.setForeground(new java.awt.Color(102, 102, 255));
        cbVacFillVacId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btnVacFillUpdate.setForeground(new java.awt.Color(102, 102, 255));
        btnVacFillUpdate.setText("Update");
        btnVacFillUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVacFillUpdateActionPerformed(evt);
            }
        });

        btnVacFillDelete.setForeground(new java.awt.Color(102, 102, 255));
        btnVacFillDelete.setText("Delete");
        btnVacFillDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVacFillDeleteActionPerformed(evt);
            }
        });

        lblVacFillVacIdCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacFillVacIdCheck.setText("Need To choice one Vacancy ID");

        cbVacFillEmpId.setForeground(new java.awt.Color(102, 102, 255));
        cbVacFillEmpId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel3.setForeground(new java.awt.Color(102, 102, 255));
        jLabel3.setText("Employee ID:");

        jLabel4.setForeground(new java.awt.Color(102, 102, 255));
        jLabel4.setText("Fill Date:");

        btnVacFillCancel.setForeground(new java.awt.Color(102, 102, 255));
        btnVacFillCancel.setText("Cancel");

        lblVacFillDateCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacFillDateCheck.setText("Fill Date Cannot be blank");

        jLabel5.setForeground(new java.awt.Color(102, 102, 255));
        jLabel5.setText("Intake Details:");

        txaVacFillInDetail.setColumns(20);
        txaVacFillInDetail.setForeground(new java.awt.Color(102, 102, 255));
        txaVacFillInDetail.setRows(5);
        jScrollPane1.setViewportView(txaVacFillInDetail);

        lblVacFillInDetailsCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacFillInDetailsCheck.setText("Intake Details Cannot be blank");

        lblVacFillEmpIdCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacFillEmpIdCheck.setText("Need To choice Employee ID");

        btnfind.setText("Find");
        btnfind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnfindActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(136, 136, 136)
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(88, 88, 88)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(39, 39, 39)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblVacFillInDetailsCheck, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblVacFillDateCheck, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(45, 45, 45)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbVacFillEmpId, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lblVacFillEmpIdCheck, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 6, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(txtVacFillDate, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(51, 51, 51)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtVacFillID, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblVacFillVacIdCheck, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cbVacFillVacId, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnVacFillCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnVacFillDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnVacFillUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnfind, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(9, 9, 9)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtVacFillID, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnfind, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(cbVacFillVacId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(lblVacFillVacIdCheck)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(cbVacFillEmpId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(21, 21, 21)
                        .addComponent(lblVacFillEmpIdCheck)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtVacFillDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(lblVacFillDateCheck)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(btnVacFillUpdate)
                        .addGap(50, 50, 50)
                        .addComponent(btnVacFillDelete)
                        .addGap(50, 50, 50)
                        .addComponent(btnVacFillCancel)))
                .addGap(18, 18, 18)
                .addComponent(lblVacFillInDetailsCheck)
                .addGap(71, 71, 71))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVacFillUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVacFillUpdateActionPerformed
        if (validateVacFillUpdateDelete()) {

            String VacId = cbVacFillVacId.getSelectedItem().toString().trim();
            String EmpId = cbVacFillEmpId.getSelectedItem().toString().trim();
            String FillDate = txtVacFillDate.getText().trim();
            String InDetail = txaVacFillInDetail.getText().trim();

            Vector v = new Vector();
            v.add(VacId);
            v.add(EmpId);
            v.add(FillDate);
            v.add(InDetail);


            if (!validateVacFillUpdateDelete()) {
                return;
            }

            if (!vacFillDao.updatateVacFill(v)) {
                JOptionPane.showMessageDialog(this, "Cannot Update! Please try again!", "UPDATE VACANCIES FILL DETAIL", JOptionPane.ERROR_MESSAGE);
                return;
            }
            JOptionPane.showMessageDialog(this, "Update new VACANCIES Fill Detail successfully!", "UPDATE VACANCIES FILL DETAIL", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_btnVacFillUpdateActionPerformed

    private void btnVacFillDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVacFillDeleteActionPerformed
        String VacID = cbVacFillVacId.getSelectedItem().toString().trim();

        if (!vacFillDao.deleteVacFill(VacID)) {
            JOptionPane.showMessageDialog(this, "Cannot DELETE! Please try again!", "DELETE VACANCIES", JOptionPane.ERROR_MESSAGE);
            return;
        }
        JOptionPane.showMessageDialog(this, "DELETE VACANCIES successfully!", "DELETE VACANCIES", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_btnVacFillDeleteActionPerformed

    private void btnfindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnfindActionPerformed
        Vector vecVacFillData = vacFillDao.loadVacFillToUpdate(txtVacFillID.getText().trim());

        cbVacFillVacId.setSelectedItem(vecVacFillData.get(0).toString());
        cbVacFillEmpId.setSelectedItem(vecVacFillData.get(1).toString());
        txtVacFillDate.setText(vecVacFillData.get(2).toString());
        txaVacFillInDetail.setText(vecVacFillData.get(3).toString());
    }//GEN-LAST:event_btnfindActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(updateDeleteVacFill.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(updateDeleteVacFill.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(updateDeleteVacFill.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(updateDeleteVacFill.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new updateDeleteVacFill().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnVacFillCancel;
    private javax.swing.JButton btnVacFillDelete;
    private javax.swing.JButton btnVacFillUpdate;
    private javax.swing.JButton btnfind;
    private javax.swing.JComboBox cbVacFillEmpId;
    private javax.swing.JComboBox cbVacFillVacId;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblVacFillDateCheck;
    private javax.swing.JLabel lblVacFillEmpIdCheck;
    private javax.swing.JLabel lblVacFillInDetailsCheck;
    private javax.swing.JLabel lblVacFillVacIdCheck;
    private javax.swing.JTextArea txaVacFillInDetail;
    private javax.swing.JTextField txtVacFillDate;
    private javax.swing.JTextField txtVacFillID;
    // End of variables declaration//GEN-END:variables
}
